/*jslint browser: true, nomen: true, es5: true*/
/*global $, jQuery, window, requirejs, require, define*/
/*实现python中str的format方法”*/
String.prototype.format = function (replace_dict) {
    "use strict";
    var result = this,
        key,
        value,
        reg,
        index;
    for (key in replace_dict) {
        if (replace_dict.hasOwnProperty(key)) {
            value = replace_dict[key];
            reg = new RegExp("({" + key + "})", "g");
            result = result.replace(reg, value);
        }
    }
    return result;
};
/*去除字符串首尾的空格，中间的空格保留*/
function trim(s) {
    "use strict";
    return s.replace(/(^\s*)|(\s*$)/g, "");
}
function getToday(dateData) {
    "use strict";
    var aDate = dateData || new Date(),
        year = aDate.getFullYear(),
        month = aDate.getMonth() + 1,
        day = aDate.getDate(),
        date_list = [];
    date_list.push(year);
    if (month < 10) {
        date_list.push("0"  + String(month));
    } else {
        date_list.push(month);
    }
    if (day < 10) {
        date_list.push("0"  + String(day));
    } else {
        date_list.push(day);
    }
    return date_list.join("-");
}
function getTodayInt(dateData) {
    "use strict";
    var aDate = dateData || new Date(),
        year = aDate.getFullYear(),
        month = aDate.getMonth() + 1,
        day = aDate.getDate(),
        date_list = [];
    return year * 10000 + month * 100 + day;
}
function getMonth(dateData) {
    "use strict";
    var aDate = dateData || new Date(),
        year = aDate.getFullYear(),
        month = aDate.getMonth() + 1,
        date_list = [];
    date_list.push(year);
    if (month < 10) {
        date_list.push("0"  + String(month));
    } else {
        date_list.push(month);
    }
    return date_list.join("-");
}
function getMonthInt(dateData) {
    "use strict";
    var aDate = dateData || new Date(),
        year = aDate.getFullYear(),
        month = aDate.getMonth() + 1;
    return year * 100 + month;
    
}
function dateStr2Int(dateData) {
    "use strict";
    var dateList = dateData.split("-"),
        year = parseInt(dateList[0], 10),
        month =  parseInt(dateList[1], 10),
        day =  parseInt(dateList[2], 10);
    return year * 10000 + month * 100 + day;
}
function dateInt2Str(dateData) {
    "use strict";
    var year = parseInt(dateData / 10000, 10),
        month = parseInt((dateData - year * 10000) / 100, 10),
        day = parseInt((dateData - year * 10000 - month * 100), 10),
        dateList = [year, month, day];
    return getToday(new Date(dateList.join("-")));
}
/*update 中，查找变化的值*/
function getChangedValue(new_data, old_data) {
    "use strict";
    var transData = {},
        var_name,
        new_data_value,
        old_data_value,
        not_changed = true;
    for (var_name in old_data) {
        if (old_data.hasOwnProperty(var_name) && new_data.hasOwnProperty(var_name)) {
            old_data_value = old_data[var_name];
            new_data_value = new_data[var_name];
            if (old_data_value instanceof Array) {
                if (old_data_value.toString() !== new_data_value.toString()) {
                    transData[var_name] = new_data_value;
                    not_changed = false;
                }
            } else {
                if (old_data_value !== new_data_value) {
                    transData[var_name] = new_data_value;
                    not_changed = false;
                }
            }
        }
    }
    if (not_changed) {
        return false;
    } else {
        return transData;
    }
}
define("lhmcv.public", {});